﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using B2BCore;

namespace B2BClient
{
    /// <summary>
    /// Class for global functions
    /// </summary>
    public class GlobalFunctions
    {
        /// <summary>
        /// Function to populate server list
        /// </summary>
        public static void populateServerList()
        {
            LogHelper.Log("Server List Population", System.Diagnostics.TraceEventType.Start);
            if (File.Exists("servers.ini"))
            {
                TextReader reader = new StreamReader("servers.ini");
                string servers;
                servers = reader.ReadToEnd();
                reader.Close();
                string[] serverssplit = Regex.Split(servers, "\r\n");

                foreach (string s in serverssplit)
                {
                    GlobalVariables.Server server;
                    server.address = s;

                    GlobalVariables.serverList.Add(server);
                    LogHelper.Log(string.Format("Server Added: {0}", server.address), System.Diagnostics.TraceEventType.Verbose, "Variables : ServerList");
                }
                LogHelper.Log("Server List Population", System.Diagnostics.TraceEventType.Stop);
            }
            else
            {
                LogHelper.Log("Server List Doesnt Exist, creating blank list", System.Diagnostics.TraceEventType.Error);
                File.Create("servers.ini");
            }
        }
    }
}
